package network.TCP;

import java.util.Date;

/**
 * Project ChatSystemG6 - INSA 4INFOA1 -
 *         2013/2014
 *         <P>
 *         <li> class Speed : calculate the file transfer speed </li>
 * @author Christelle SIAGO HAPPI  
 */

public class Speed {

	/**
	 * @param timeNow
	 *            the current time
	
	 * @param speed
	 *            : the File transfer speed
	 */
	private long timeNow, deltaTime, speed;
	
	/**
	 * @param TraityOctect
	 *            :byte being processed
	 */
	private int TraityOctect;

	/**
	 * Constructor Initializes the custom attributes to zero
	 */
	public Speed() {
		timeNow = 0;
		deltaTime = 0;
		speed = 0;
		TraityOctect = 0;
	}

	/**
	 * @return Transfer Speed value
	 */
	public long getSpeedValue() {
		return speed;
	}

	/**
	 * @return transfer speed
	 */
	public long getSpeed(long timeDebut, int octetTraite) {
		calculateSpeed(timeDebut, octetTraite);
		return speed;
	}

	/**
	 * @return TraityOctect
	 */
	public int getOctectProceed() {
		return TraityOctect;
	}

	/**
	 * calculates the speed of a transfer
	 * 
	 * @param StartTime
	 *            start time of transfer
	 * @return octetRead TreatyOctet treated for transfer
	 */
	private void calculateSpeed(long StartTime, int TreatyOctet) {
		this.TraityOctect = TreatyOctet;
		timeNow = new Date().getTime();
		deltaTime = (timeNow - StartTime) / 1000;
		if (deltaTime == 0)
			deltaTime = 1;
		speed = TreatyOctet / deltaTime;

	}

}
